﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace GroupChat2013.Common
{
    /// <summary>
    /// 文件路径管理
    /// </summary>
    public class FilePathManager
    {
        /// <summary>
        /// 当前用户ID
        /// </summary>
        private string curUserId;

        /// <summary>
        /// 根目录
        /// </summary>
        private string basePath;

        /// <summary>
        /// 个人根目录
        /// </summary>
        private string myBasePath;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="curUserId">当前用户ID</param>
        /// <param name="basePath">更目录</param>
        public FilePathManager(string curUserId, string basePath)
        {
            this.curUserId = curUserId;
            this.basePath = basePath;

            if (string.IsNullOrEmpty(this.basePath))
            {
                this.basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GroupChat Files");
            }

            myBasePath = Path.Combine(this.basePath, curUserId);
        }

        private string _imagePath;
        /// <summary>
        /// 发送图片路径 比如截图
        /// </summary>
        public string ImagePath
        {
            get
            {
                if (string.IsNullOrEmpty(_imagePath))
                {
                    _imagePath = Path.Combine(myBasePath, "Image");
                    Tools.CreateDir(_imagePath);
                }

                return _imagePath;
            }
        }

        private string _dbPath;

        /// <summary>
        /// 个人相关信息数据库
        /// </summary>
        public string DbPath
        {
            get
            {
                if (string.IsNullOrEmpty(_dbPath))
                {
                    _dbPath = Path.Combine(myBasePath, "Data");
                    Tools.CreateDir(_dbPath);
                }

                return _dbPath;
            }
        }

        private string _PersonConfigPath;

        /// <summary>
        /// 个人相关配置信息
        /// </summary>
        public string PersonConfigPath
        {
            get
            {
                if (string.IsNullOrEmpty(_PersonConfigPath))
                {
                    _PersonConfigPath = Path.Combine(myBasePath, "Config");
                    Tools.CreateDir(_PersonConfigPath);
                }

                return _PersonConfigPath;
            }
        }
    }
}
